package ${package.ServiceImpl};

<#--import com.debao.cloud.modules.carbon.dto.${entity}DTO;-->
<#--import com.debao.cloud.modules.carbon.vo.${entity}PageVO;-->
<#--import com.debao.cloud.modules.carbon.vo.${entity}ListVO;-->
<#--import com.debao.cloud.modules.carbon.vo.${entity}InfoVO;-->
<#--import com.debao.cloud.modules.carbon.service.${entity}Service;-->
<#--import com.debao.cloud.common.entity.business.model.po.${entity}PO;-->
<#--import com.debao.cloud.common.entity.business.mapper.${entity}Mapper;-->
<#assign myDateType = ["LocalDateTime","LocalDate"]/>
<#--import ${package.Mapper}.${entity}Mapper;-->
<#--import ${package.Service}.${entity}Service;-->
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.hutool.core.lang.Assert;

/**
 * ${table.comment!}实现层
 *
 * @author ${author}
 * @date ${date}
 */
@Slf4j
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}PO> implements ${table.serviceName} {

    @Resource
    private ${table.mapperName} ${table.mapperName?uncap_first};

    @Override
    public Page<${table.entityName}PageVO> listPage(Page<${table.entityName}PO> page, ${table.entityName}DTO dto) {
        // 设置查询条件并按创建时间倒序
        LambdaQueryWrapper<${table.entityName}PO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.setEntity(dto).orderByDesc(${table.entityName}PO::getGmtCreate);
        // 获取数据后，转VO返回
        Page<${table.entityName}PO> pagePo = ${table.mapperName?uncap_first}.selectPage(page, queryWrapper);
        return PageUtil.getPageVO(pagePo, BeanUtil.copyToList(pagePo.getRecords(), ${table.entityName}PageVO.class));
    }

    @Override
    public List<${table.entityName}DTO> list(${table.entityName}DTO dto) {
        LambdaQueryWrapper<${table.entityName}PO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.setEntity(dto).orderByDesc(${table.entityName}PO::getGmtCreate);
        List<${table.entityName}PO> poList = ${table.mapperName?uncap_first}.selectList(queryWrapper);
        return BeanUtil.copyToList(poList, ${table.entityName}DTO.class);
    }

    @Override
    public void insert(${table.entityName}DTO dto) {
        int insertNum = ${table.mapperName?uncap_first}.insert(dto);
        Assert.isTrue(insertNum == 1, () -> new ApiException("新增${table.comment!}失败"));
    }

    @Override
    public void updateById(${table.entityName}DTO dto) {
        int updateNum = ${table.mapperName?uncap_first}.updateById(dto);
        Assert.isTrue(updateNum == 1, () -> new ApiException("修改${table.comment!}失败"));
    }

    @Override
    public ${table.entityName}DTO getById(Integer id) {
        ${table.entityName}PO po = ${table.mapperName?uncap_first}.selectById(id);
        return po == null ? null : BeanUtil.copyProperties(po, ${table.entityName}DTO.class);
    }

}
</#if>
